package com.ruoyi.quotation.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.quotation.domain.QuoPricing;
import com.ruoyi.quotation.domain.QuoQuote;
import com.ruoyi.quotation.service.IQuoPricingService;
import com.ruoyi.quotation.service.IQuoManagerService;
import com.ruoyi.quotation.vo.QuoteEngineeringVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 总经理审核Controller
 */
@RestController
@RequestMapping("/quotation/manager")
public class QuoManagerController extends BaseController {

    @Autowired
    private IQuoManagerService quoManagerService;

    /**
     * 查询待审核列表
     */
    @PreAuthorize("@ss.hasPermi('quotation:manager:list')")
    @GetMapping("/list")
    public TableDataInfo list(QuoQuote quoQuote) {
        startPage();
        List<QuoQuote> list = quoManagerService.selectManagerQuoteList(quoQuote);
        return getDataTable(list);
    }

    /**
     * 导出待审核列表
     */
    @PreAuthorize("@ss.hasPermi('quotation:manager:export')")
    @Log(title = "总经理审核", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, QuoQuote quoQuote) {
        List<QuoQuote> list = quoManagerService.selectManagerQuoteList(quoQuote);
        // 使用Excel工具类导出
    }

    /**
     * 获取报价详情
     */
    @PreAuthorize("@ss.hasPermi('quotation:manager:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id) {
        return success(quoManagerService.getQuoteFullInfo(id));
    }

    /**
     * 执行总经理审核
     */
    @PreAuthorize("@ss.hasPermi('quotation:manager:audit')")
    @Log(title = "总经理审核", businessType = BusinessType.UPDATE)
    @PostMapping("/audit")
    public AjaxResult audit(@RequestBody QuoQuote quoQuote) {
        return toAjax(quoManagerService.auditQuote(quoQuote));
    }

    /**
     * 驳回审核
     */
    @PreAuthorize("@ss.hasPermi('quotation:manager:reject')")
    @Log(title = "驳回审核", businessType = BusinessType.UPDATE)
    @PostMapping("/reject")
    public AjaxResult reject(@RequestBody QuoQuote quoQuote) {
        return toAjax(quoManagerService.rejectQuote(quoQuote));
    }
} 